
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_opengl.h"
#include "GL/glut.h"

#include <cmath>
#include <time.h>

#include "headers/Defines.h"
#include "headers/SkyBox.h"
#include "headers/Utils.h"

#include <iostream>
using namespace std;

#include "headers/Config.h"
#include "headers/Vector3d.h"
#include "headers/Camera.h"
#include "headers/KeyBoardState.h"
#include "headers/SpaceShip.h"
#include "headers/Model3d.h"
#include "headers/HellGate.h"
#include "headers/Sweep.h"
#include "headers/objloader.h"

bool show_bridge = true;
bool show_castles = true;
bool show_pillers = true;
bool show_trains = true;

bool trains_moving = true;

bool axis_visible = false;

unsigned int waterTex;

//train variables
float train1_pos = -0;
float train2_pos = 0;

#define TRAINSPEED 80

#define MAX_TRAIN_DIST 800

#define  MOVEMENT_SPEED 100.0f     //per second NOT per draw call
#define  ROTATION_SPEED 50.0f
#define  SKY_BRIGHTNESS_CHANGE_SPEED 0.5f
enum {
	DAWN = 0, DAY, NIGHT, EVENING
};

float angle = 0;
float SKY_BRIGHTNESS = 1.0f;
float dawnInc = 1.0 / 30.0;

float nightInc = -1.0 / 180.0;
unsigned int dayState;
unsigned int dlist_bridge;
unsigned int dlist_castles;
unsigned int dlist_pillars;
unsigned int dlist_train1;
unsigned int dlist_terrain;
unsigned int dlist_full_bridge;

float zeros[] = { 0, 0, 0, 0 };
float ones[] = { 1, 1, 1, 1 };

objloader obj;

float water1_pos,water2_pos;


bool auto_movement_of_object = false;

float sun_angle = 0;
float SUN_ROT_SPEED = 15.0f;

Camera *camera;
SpaceShip *model;

clock_t last_display_time = 0;
double deltaTime() {
	clock_t current_time = clock();
	double delta_time = current_time - last_display_time;
	last_display_time = current_time;
	return delta_time / CLOCKS_PER_SEC;

}

void camera_setup(double delta_time) {

	//Transform *camera = &(model->transform);
	//translation
	if (KeyBoardState::keyPressed_up) {
		camera->walk(MOVEMENT_SPEED * delta_time);
	} else if (KeyBoardState::keyPressed_down) {
		camera->walk(-MOVEMENT_SPEED * delta_time);
	}
	if (KeyBoardState::keyPressed_left) {
		camera->strafe(-MOVEMENT_SPEED * delta_time);
	} else if (KeyBoardState::keyPressed_right) {
		camera->strafe(MOVEMENT_SPEED * delta_time);
	}
	if (KeyBoardState::keyPressed_lshift) {
		camera->fly(MOVEMENT_SPEED * delta_time);
	} else if (KeyBoardState::keyPressed_space) {
		camera->fly(-MOVEMENT_SPEED * delta_time);
	}

	//rotation
	if (KeyBoardState::keyPressed_w) {
		camera->pitch(ROTATION_SPEED * delta_time);
	} else if (KeyBoardState::keyPressed_s) {
		camera->pitch(-ROTATION_SPEED * delta_time);
	}
	if (KeyBoardState::keyPressed_a) {
		camera->yaw(ROTATION_SPEED * delta_time);
	} else if (KeyBoardState::keyPressed_d) {
		camera->yaw(-ROTATION_SPEED * delta_time);
	}
	if (KeyBoardState::keyPressed_q) {
		camera->roll(ROTATION_SPEED * delta_time);
	} else if (KeyBoardState::keyPressed_e) {
		camera->roll(-ROTATION_SPEED * delta_time);
	}
}

void object_setup(double delta_time) {

	Transform * transform = &(model->transform);

	if (KeyBoardState::keyPressed_t) {
		transform->walk(-MOVEMENT_SPEED * delta_time);
	} else if (KeyBoardState::keyPressed_g) {
		transform->walk(MOVEMENT_SPEED * delta_time);
	}
	if (KeyBoardState::keyPressed_f) {
		transform->strafe(MOVEMENT_SPEED * delta_time);
	} else if (KeyBoardState::keyPressed_h) {
		transform->strafe(-MOVEMENT_SPEED * delta_time);
	}
	if (KeyBoardState::keyPressed_r) {
		transform->fly(MOVEMENT_SPEED * delta_time);
	} else if (KeyBoardState::keyPressed_y) {
		transform->fly(-MOVEMENT_SPEED * delta_time);
	}

	//rotation
	if (KeyBoardState::keyPressed_i) {
		transform->pitch(-ROTATION_SPEED * delta_time);
	} else if (KeyBoardState::keyPressed_k) {
		transform->pitch(ROTATION_SPEED * delta_time);
	}
	if (KeyBoardState::keyPressed_j) {
		transform->yaw(ROTATION_SPEED * delta_time);
	} else if (KeyBoardState::keyPressed_l) {
		transform->yaw(-ROTATION_SPEED * delta_time);
	}
	if (KeyBoardState::keyPressed_u) {
		transform->roll(ROTATION_SPEED * delta_time);
	} else if (KeyBoardState::keyPressed_o) {
		transform->roll(-ROTATION_SPEED * delta_time);
	}

}

void auto_object_move(double delta_time) {
	Transform * transform = &(model->transform);

	if ((transform->getPosition()).z > 300) {
		Vector3d v(0.0f, 0.0f, -300.0f);
		transform->setPosition(v);
	}
	transform->walk(-MOVEMENT_SPEED * delta_time);
}

void drawLightPoint(GLfloat lightPos0[]) {

	glPushAttrib(GL_ALL_ATTRIB_BITS);
	GLfloat redEmissiveMaterial[] = { 1.0f, 0.0f, 0.0f, 1.0f };
	glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, redEmissiveMaterial);
	glColor3f(0.8f, 0.8f, 0.0f);
	glPushMatrix();
	glTranslatef(lightPos0[0], lightPos0[1], lightPos0[2]);
	glutSolidSphere(2.5f, 30, 30);
	glPopMatrix();
	GLfloat blankMaterial[] = { 0.0f, 0.0f, 0.0f, 0.0f };
	glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, blankMaterial);
	glPopAttrib();
}

void drawExis(float len, float gap) {
	//drawing axis

	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glDisable(GL_LIGHTING);
	//drawSphere(len, 0, 0);
	//drawSphere(0, len, 0);
	//drawSphere(0, 0, len);
	glBegin(GL_LINES);
	{

		glColor3f(1.0f, 0.0f, 0.0f);

		glVertex3f(len, 0.0f, 0);
		glVertex3f(-len, 0.0f, 0);
		glColor3f(0.0f, 1.0f, 0.0f);
		glVertex3f(0.0f, len, 0);
		glVertex3f(0.0f, -len, 0);
		glColor3f(0.0f, 0.0f, 1.0f);
		glVertex3f(0.0f, 0.0f, len);
		glVertex3f(0.0f, 0.0f, -len);
	}
	glEnd();

	glColor3fv(Config::grid_color);
	for (int i = -len; i <= len; i += gap) {
		glPushMatrix();
		glTranslatef(0, 0, i);
		glBegin(GL_LINES);

		glVertex3f(len, 0.0f, 0);
		glVertex3f(-len, 0.0f, 0);
		glEnd();
		glPopMatrix();
		glPushMatrix();
		glTranslatef(i, 0, 0);
		glBegin(GL_LINES);
		glVertex3f(0.0f, 0.0f, len);
		glVertex3f(0.0f, 0.0f, -len);
		glEnd();
		glPopMatrix();

	}
	glPopAttrib();
}

void setUpLighting() {
	//ambient lighting
	GLfloat ambientColor[] = { 0.2f, 0.2f, 0.2f, 1.0f };
	//glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
	//point light
	GLfloat lightColor0[] = { SKY_BRIGHTNESS, SKY_BRIGHTNESS, SKY_BRIGHTNESS,
			SKY_BRIGHTNESS };
	GLfloat lightPos0[] = { 0.0f, 1.0f, 0.0f, 0.0f };
	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);
	glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);
	drawLightPoint(lightPos0);
	//directional light
	GLfloat lightColor1[] = { 0.5f, 0.5f, 0.5f, 1.0f };
	GLfloat lightColor_spec1[] = { 0.8f, 0.8f, 0.8f, 8.0f };
	GLfloat lightPos1[] = { 1.0f, 1.0f, 1.0f, 0.0f };
	glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1);
	glLightfv(GL_LIGHT1, GL_SPECULAR, lightColor_spec1);
	glLightfv(GL_LIGHT1, GL_AMBIENT, ambientColor);
	glLightfv(GL_LIGHT1, GL_POSITION, lightPos1);
}

void display(void)

{
	//glPushAttrib(GL_ALL_ATTRIB_BITS);

	//find delta time for display function
	float delta_time = deltaTime();
	/* clear window */

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	camera_setup(delta_time);
	camera->update();

	//     if (KeyBoardState::keyPressed_f1) {
	//		SKY_BRIGHTNESS -= SKY_BRIGHTNESS_CHANGE_SPEED * delta_time;
	//		if (SKY_BRIGHTNESS < 0)
	//			SKY_BRIGHTNESS = 0;
	//	}
	//	if (KeyBoardState::keyPressed_f2) {
	//		SKY_BRIGHTNESS += SKY_BRIGHTNESS_CHANGE_SPEED * delta_time;
	//		if (SKY_BRIGHTNESS > 1)
	//			SKY_BRIGHTNESS = 1;
	//	}


	if (KeyBoardState::keyPressed_f7)
		glEnable(GL_LIGHT1);
	else
		glDisable(GL_LIGHT1);
	if (!KeyBoardState::keyPressed_f6)
		sun_angle += SUN_ROT_SPEED * delta_time;
	if (sun_angle > 360)
		sun_angle -= 360;
	if (sun_angle < 180)
		SKY_BRIGHTNESS = sin(3 * sun_angle * PI / 180.0);
	else
		SKY_BRIGHTNESS = 0;

	if (sun_angle > 30 && sun_angle < 150) {
		SKY_BRIGHTNESS = 1;
		glDisable(GL_LIGHT2);
		glDisable(GL_LIGHT3);
	} else {
		glEnable(GL_LIGHT2);
		glEnable(GL_LIGHT3);
	}

	glPushMatrix();
	{
		Vector3d cam_pos = camera->getPosition();
		glTranslatef(cam_pos.x, cam_pos.y, cam_pos.z);
		drawSkyboxNight(10, 1.0);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		drawSkybox(10, SKY_BRIGHTNESS);
	}
	glPopMatrix();

	glPushMatrix();
	{
		glRotatef(sun_angle - 90, 1.0f, 0.0f, 0.0f);
		glTranslatef(0, 400, 0);
		setUpLighting();
	}
	glPopMatrix();

	//drawing axis
	if (axis_visible)
		drawExis(160, 40);

	//glutSolidCube(20.0f);

	if (auto_movement_of_object == false) {
		object_setup(delta_time);
	} else {
		auto_object_move(delta_time);
	}

	glPushAttrib(GL_ALL_ATTRIB_BITS);
	{
		glPushMatrix();
		{
			glTranslatef(0, -5.3, 0);
			glEnable(GL_TEXTURE_2D);
			glDisable(GL_COLOR_MATERIAL);
			if (show_trains) {
				glPushMatrix();
				{
					if (trains_moving)
						train1_pos += TRAINSPEED * delta_time;
					if (train1_pos > MAX_TRAIN_DIST) {
						train1_pos = -MAX_TRAIN_DIST;
					}
					glTranslatef(train1_pos, 0, -1);
					float pos[] = { 70, 5, 0, 1 };
					float col[] = { 1, 1, 1, 1 };
					glLightfv(GL_LIGHT2, GL_POSITION, pos);
					glLightfv(GL_LIGHT2, GL_COLOR, col);
					glLightfv(GL_LIGHT2, GL_DIFFUSE, col);
					glCallList(dlist_train1);
				}
				glPopMatrix();
				glPushMatrix();
				{
					if (trains_moving)
						train2_pos -= TRAINSPEED * delta_time;
					if (train2_pos < -MAX_TRAIN_DIST) {
						train2_pos = MAX_TRAIN_DIST;
					}
					glTranslatef(train2_pos, 0, 4.5);
					float pos[] = { -70, 5, 0, 1 };
					float col[] = { 1, 1, 1, 1 };

					glLightfv(GL_LIGHT3, GL_POSITION, pos);
					glLightfv(GL_LIGHT3, GL_COLOR, col);
					glLightfv(GL_LIGHT3, GL_DIFFUSE, col);
					glCallList(dlist_train1);
				}
				glPopMatrix();
			}
		}
		glPopMatrix();
	}
	glPopAttrib();

	if (show_bridge)glCallList(dlist_bridge);


	glPushAttrib(GL_ALL_ATTRIB_BITS);
	{
		glEnable(GL_TEXTURE_2D);
		glDisable(GL_COLOR_MATERIAL);
		if (show_castles)
			glCallList(dlist_castles);
		if (show_pillers)
			glCallList(dlist_pillars);
	}
	glPopAttrib();

	glPushAttrib(GL_ALL_ATTRIB_BITS);

	// glRotatef(-90,1.0f,0.0f,0.0f);
	//glRotatef(55,0.0f,0.0f,1.0f);


	glPushMatrix();
	{
		glTranslatef(40, -80, 10);
		glRotatef(-90, 1.0f, 0.0f, 0.0f);
		glRotatef(55, 0.0f, 0.0f, 1.0f);
		glCallList(dlist_terrain);
	}
	glPopMatrix();

	glPushMatrix();
	{
		glTranslatef(0, -50, 0);

		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, waterTex);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		glDepthMask(GL_FALSE);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glColor4f(0.7, 0.7, 0.7, 0.7);

		float rep = 5;
		glBegin(GL_QUADS);
		{
			//glColor3f(0,0,.5);
			glTexCoord2f(rep, 0);
			glVertex3f(-500, 0, 0);
			glTexCoord2f(0, 0);
			glVertex3f(50, 0, 650);
			glTexCoord2f(0, rep);
			glVertex3f(500, 0, 0);
			glTexCoord2f(rep, rep);
			glVertex3f(0, 0, -700);

		}
		glEnd();

	}
	glPopMatrix();

	glPopAttrib();

	//glPopAttrib();



	SDL_GL_SwapBuffers();

}

void init() {

	KeyBoardState::keyPressed_f7 = true;
	waterTex = loadTexture("image/water.jpg", GL_UNSIGNED_BYTE, GL_RGB);

	initskyboxnight();
	initskybox();
	HellGate::initTexture();
	camera = new Camera();
	camera->reset();
	camera->walk(-70);
	model = new SpaceShip();
	last_display_time = clock();
	// glEnable(GL_CULL_FACE);
	// glCullFace(GL_BACK);
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHT1);
	glEnable(GL_LIGHT2);
	glEnable(GL_LIGHT3);

	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_NORMALIZE);
	glShadeModel(GL_SMOOTH);

	dlist_full_bridge = glGenLists(1);
	glNewList(dlist_bridge, GL_COMPILE);
	{
		HellGate().draw();
	}
	glEndList();

	//setUpLighting();
	dlist_bridge = glGenLists(1);
	glNewList(dlist_bridge, GL_COMPILE);
	{
		HellGate().DrawMainBridge();
	}
	glEndList();

	dlist_castles = glGenLists(1);
	glNewList(dlist_castles, GL_COMPILE);
	{
		HellGate().DrawCastles();
	}
	glEndList();

	dlist_pillars = glGenLists(1);
	glNewList(dlist_pillars, GL_COMPILE);
	{
		HellGate().DrawPillers();
	}
	glEndList();

	//Materials of the spaceship
	GLfloat whiteSpecularMaterial[] = { 0.0f, 0.1f, 0.1f, 0.0f };
	GLfloat whiteDifuseMaterial[] = { 0.7f, 0.7f, 0.1f, 1.0f };
	//GLfloat mShininess[] = {1.5f,1.5f,1.5f,1.0f};
	//glMaterialfv(GL_FRONT, GL_SPECULAR, whiteSpecularMaterial);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, whiteDifuseMaterial);
	//glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mShininess);


	dlist_train1 = obj.load("object/bullettrain.obj");
	dlist_terrain = obj.load("object/color_terrain.obj");

}

void resize(int w, int h) {
	glViewport(0, 0, w, h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(50, w / (float) h, 1.0f, 10000.0f);

}

void keyBoardDownEventHandler(SDL_Event& event) {
	switch (event.key.keysym.sym) {
	case SDLK_LEFT:
		KeyBoardState::keyPressed_left = true;
		break;
	case SDLK_RIGHT:
		KeyBoardState::keyPressed_right = true;
		break;
	case SDLK_UP:
		KeyBoardState::keyPressed_up = true;
		break;
	case SDLK_DOWN:
		KeyBoardState::keyPressed_down = true;
		break;
	case SDLK_SPACE:
		KeyBoardState::keyPressed_space = true;
		break;
	case SDLK_LSHIFT:
		KeyBoardState::keyPressed_lshift = true;
		break;
	case SDLK_w:
		KeyBoardState::keyPressed_w = true;
		break;
	case SDLK_s:
		KeyBoardState::keyPressed_s = true;
		break;
	case SDLK_a:
		KeyBoardState::keyPressed_a = true;
		break;
	case SDLK_d:
		KeyBoardState::keyPressed_d = true;
		break;
	case SDLK_q:
		KeyBoardState::keyPressed_q = true;
		break;
	case SDLK_e:
		KeyBoardState::keyPressed_e = true;
		break;
	case SDLK_r:
		camera->reset();
		break;
	case SDLK_b:
		show_bridge = !show_bridge;
		break;
	case SDLK_c:
		show_castles = !show_castles;
		break;
	case SDLK_p:
		show_pillers = !show_pillers;
		break;
	case SDLK_t:
		show_trains = !show_trains;
		break;
	case SDLK_m:
		trains_moving = !trains_moving;
		break;
	case SDLK_F1:
		KeyBoardState::keyPressed_f1 = true;
		SKY_BRIGHTNESS -= SKY_BRIGHTNESS_CHANGE_SPEED * deltaTime();
		if (SKY_BRIGHTNESS < 0)
			SKY_BRIGHTNESS = 0;
		break;
	case SDLK_F2:
		KeyBoardState::keyPressed_f2 = true;
		SKY_BRIGHTNESS += SKY_BRIGHTNESS_CHANGE_SPEED * deltaTime();
		if (SKY_BRIGHTNESS > 1)
			SKY_BRIGHTNESS = 1;
		break;

	case SDLK_F4:
		SUN_ROT_SPEED -= 5;
		break;
	case SDLK_F5:
		SUN_ROT_SPEED += 5;
		break;

	case SDLK_F6:
		KeyBoardState::keyPressed_f6 = !KeyBoardState::keyPressed_f6;
		break;
	case SDLK_F7:
		KeyBoardState::keyPressed_f7 = !KeyBoardState::keyPressed_f7;
		break;

	case SDLK_F3:
		axis_visible = !axis_visible;
		break;
	default:
		break;
	}
}

void keyBoardUpEventHandler(SDL_Event& event) {
	switch (event.key.keysym.sym) {
	case SDLK_LEFT:
		KeyBoardState::keyPressed_left = false;
		break;
	case SDLK_RIGHT:
		KeyBoardState::keyPressed_right = false;
		break;
	case SDLK_UP:
		KeyBoardState::keyPressed_up = false;
		break;
	case SDLK_DOWN:
		KeyBoardState::keyPressed_down = false;
		break;
	case SDLK_SPACE:
		KeyBoardState::keyPressed_space = false;
		break;
	case SDLK_LSHIFT:
		KeyBoardState::keyPressed_lshift = false;
		break;
	case SDLK_w:
		KeyBoardState::keyPressed_w = false;
		break;
	case SDLK_s:
		KeyBoardState::keyPressed_s = false;
		break;
	case SDLK_a:
		KeyBoardState::keyPressed_a = false;
		break;
	case SDLK_d:
		KeyBoardState::keyPressed_d = false;
		break;
	case SDLK_q:
		KeyBoardState::keyPressed_q = false;
		break;
	case SDLK_e:
		KeyBoardState::keyPressed_e = false;
		break;
	case SDLK_F1:
		KeyBoardState::keyPressed_f1 = false;
		break;
	case SDLK_F2:
		KeyBoardState::keyPressed_f2 = false;
		break;
	default:
		break;
	}
}

#define FULL_SCREEN true

#define WIDTH 800
#define HEIGHT 600
#define WIDTH_FULL 1280
#define HEIGHT_FULL 800

int main(int argc, char** argv) {

	SDL_Init(SDL_INIT_EVERYTHING);

	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);

	SDL_Surface* screen;
	if (!FULL_SCREEN)
		screen = SDL_SetVideoMode(WIDTH, HEIGHT, 32, SDL_HWSURFACE | SDL_OPENGL
				| SDL_RESIZABLE);
	else
		screen = SDL_SetVideoMode(WIDTH_FULL, HEIGHT_FULL, 32, SDL_HWSURFACE
				| SDL_OPENGL | SDL_FULLSCREEN);
	bool running = true;
	SDL_Event event;
	init();
	//resize(WIDTH,HEIGHT);
	while (running) {
		// start=SDL_GetTicks();
		while (SDL_PollEvent(&event)) {
			switch (event.type) {
			case SDL_VIDEORESIZE:
				//screen=SDL_SetVideoMode(WIDTH,HEIGHT,32,SDL_SWSURFACE|SDL_OPENGL|SDL_RESIZABLE);
				if (screen)
					resize(screen->w, screen->h);
				break;
			case SDL_QUIT:
				running = false;
				break;
				// ## INSERT CODE TO HANDLE ANY OTHER EVENTS HERE ##
			case SDL_KEYDOWN:
				keyBoardDownEventHandler(event);
				break;
			case SDL_KEYUP:
				keyBoardUpEventHandler(event);
				break;

			}
		}

		// Check for escape
		Uint8 *keys = SDL_GetKeyState(NULL);
		if (keys[SDLK_ESCAPE]) {
			running = false;
		}

		display();
		//                angle+=1;
		//                if(angle>360)
		//                   angle-=360;
		//
		//                if(angle>0 && angle<=30)
		//                {
		//                	dayState=DAWN;
		//                	//SKY_BRIGHTNESS=0;
		//                }
		//                else if(angle>30 && angle<=150)
		//                	dayState=DAY;
		//                else if(angle>150 && angle<=180)
		//                    dayState=EVENING;
		//                else
		//                	dayState=NIGHT;
		//
		//                if(dayState==DAWN)
		//                	{
		//
		//                	SKY_BRIGHTNESS+=dawnInc;
		//                	cout<<"day"<<endl;
		//                	}
		//                else if(dayState==EVENING)
		//            {
		//                   SKY_BRIGHTNESS-=dawnInc;
		//               	cout<<"night"<<endl;
		//           }
		//
		//                else if(dayState==NIGHT)
		//                	{
		//                	SKY_BRIGHTNESS+=nightInc;
		//                	cout<<"night"<<endl;
		//                	}


	}
	killskybox();
	SDL_Quit();

	return 0;
}
